﻿using lib472.API;
using libedi.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace libedi.API
{
    public class WebAction
    {
        public ApiResult Getcert()
        {
            //cert
            string data = Clientbuss.Get("/Edi/fun",new Dictionary<string, string> { { "meth", "cert" }, { "data", "null" } });

            if (string.IsNullOrEmpty(data))
            {
                throw new ArgumentNullException(nameof(data));
            }

            return JsonConvert.DeserializeObject<ApiResult>(data);
        }

        //upcert


        public ApiResult Upcert(string Temp, string fileName)
        {
            //cert
            string data = Clientbuss.Get("/Edi/fun", new Dictionary<string, string> { { "meth", "upcert" }, { "data", $"{Temp},{fileName}" } });

            if (string.IsNullOrEmpty(data))
            {
                throw new ArgumentNullException(nameof(data));
            }

            return JsonConvert.DeserializeObject<ApiResult>(data);
        }

        //pfxinfo
        //string SignType = strings[0];
        //string file = strings[1];
        //string pwd = strings[2];
        public ApiResult GetPfxInfo(string SignType, string fileName, string pwd)
        {
            //cert
            string data = Clientbuss.Get("/Edi/fun", new Dictionary<string, string> { { "meth", "pfxinfo" }, { "data", $"{SignType},{fileName},{pwd}" } });

            if (string.IsNullOrEmpty(data))
            {
                throw new ArgumentNullException(nameof(data));
            }

            return JsonConvert.DeserializeObject<ApiResult>(data);
        }
    }
}
